<?php
/*
 * @copyright        [YouNet_COPYRIGHT]
 * @author           YouNet Company
 * @package          Module_Contactimporter
 * @version          2.06
 *
 */
defined('PHPFOX') or exit('NO DICE!');
?>
<?php
class Contactimporter_Component_Controller_Social extends Phpfox_Component
{   
    public function process()
	{
        Phpfox_Error::skip(true);
		$sProvider = $this->request()->get('req2');
        $iPage = $this->request()->get('page', 1);        
        $iLimit = $iMaxInvitation = Phpfox::getService('contactimporter')->getMaxInvitation();
        $iOffset = ($iPage - 1) * $iLimit;        
        $sPrevPage = $sNexrPage = '';
        if ($sProvider == 'facebook')
        {            
            $oFacebook = Phpfox::getService('contactimporter.facebook');
			$aProfile = $oFacebook->getProfile();
            $iCnt = $aProfile['friend_count'];
            if ($iCnt > 0)
            {
                $aInviteLists = $oFacebook->getFriends($iPage, $iLimit); 
            }
            else
            {          
                $this->url()->send('contactimporter', null, Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account'));
                exit;
            }
        }
        if ($sProvider == 'twitter')
        {            
            $oTwitter = Phpfox::getService('contactimporter.twitter');
            $aProfile = $oTwitter->getProfile();
            $iCnt = $aProfile['friend_count'];
            if ($iCnt > 0)
            {
                list($aInviteLists, $sPrevPage, $sNexrPage) = $oTwitter->getFriends($iPage, $iLimit); 
            }
            else
            {          
                $this->url()->send('contactimporter', null, Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account'));
                exit;
            }
        }
        if ($sProvider == 'linkedin')
        {
            $oLinkedIn = Phpfox::getService('contactimporter.linkedin');
            list($iCnt, $aInviteLists) = $oLinkedIn->getFriends($iPage, $iLimit); 
        }
        $this->template()->assign(array(                
            'sPrevPage' => $sPrevPage,        
            'sNexrPage' => $sNexrPage,        
            'iCnt' => $iCnt,        
            'iLimit' => $iLimit,                
            'iPage' => $iPage,                
            'sProvider' => $sProvider,                
            'aInviteLists' => $aInviteLists,                
            'aJoineds' => $aJoineds = array(),                
            'provider_box' => $sProvider,
            'sCoreUrl' =>phpfox::getParam('core.path'),
            'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
        ));
        $this->template()->setHeader(array(
            'Ynscontactimporter.css' => 'module_contactimporter',                                
            'common.js'=>'module_contactimporter',              
        ));
        Phpfox::getLib('pager')->set(array('page' => $iPage, 'size' => $iLimit, 'count' => $iCnt));        
    }
}
?>